package com.le.tester.imooc.masterJUC.threadpool;

import com.le.tester.utils.DateTimeUtilFor8;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 描述：线程池中创建固定的线程数
 */
public class FixedThreadPoolTester {
    public static void main(String[] args) {
        //使用了无界限的linkedBlockingQueue<String>，可以一直往这个队列添加任务
        //corePoolSize===maxPoolSize,使用的线程数最大也只是nThread
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        for (int i = 0; i < 1000; i++) {
            executorService.execute(new Task());
        }
    }
}

class Task implements Runnable {

    @Override
    public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage());
        }
        System.out.println("当前时间：" + DateTimeUtilFor8.time() + " 当前线程：" + Thread.currentThread().getName());
    }
}
